package com.dfdchem.imd.kaiwu.manager;

import com.dfdchem.imd.kaiwu.util.Log;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 内外网拦截器
 * @author yqq
 */
public class IntranetInterceptor implements Interceptor {
    private static final String TAG = "IntranetInterceptor";

    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request request = chain.request();
        HttpUrl url = request.url();

        String newUrl = IntranetManager.convert(url.toString());
        Log.e(TAG, url + " => " + newUrl);
        Request newRequest =  request.newBuilder()
                                .url(newUrl)
                                .headers(request.headers())
                                .build();

        return chain.proceed(newRequest);
    }
}
